# -*- coding: utf-8 -*-
# @Time    :2022/2/28 20:51
# @AUTHOR  :MORAN
# @Email   :moran@maqu.com
# @File    :modelsMixin.py
# @Software:PyCharm
from django.db import models


class IsDeleteModelsMixin(models.Model):
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    class Meta:
        abstract = True  # 定义该类为抽象类，迁移时不会创建对应的数据表，只是用于拓展让其他模型类可以继承


class DateTimeModelsMixin(models.Model):
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        abstract = True


class ModelsSetMixin(IsDeleteModelsMixin, DateTimeModelsMixin):
    pass

    class Meta:
        abstract = True
